package com.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;

public class FileUtil {
	public final static String uploadPath = "upload";// 上传文件路径

	/**
	 * 流写如文件
	 * **/
	public static boolean inputStreamToFile(InputStream ins, File file) {
		OutputStream os;
		try {
			os = new FileOutputStream(file);
			int bytesRead = 0;
			byte[] buffer = new byte[8192];
			while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
				os.write(buffer, 0, bytesRead);
			}
			os.close();
			ins.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	// 文件名称
	public static String fileName(String name) {
		return DateUtil.getDateTime("HHmmssS", new Date())
				+ SpellUtils.getFull(name);
	}

	// 目录
	public static String filePath() {
		return DateUtil.getDateTime("yyyy\\MM\\dd\\", new Date());
	}

	public static void main(String[] args) {
		System.out.println(fileName("刘dd.jpg"));
	}
}
